home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
ab20
/
ab20_archive
/
text
/
cmanual.lzh
/
ACM3.lzh
/
Miscellaneous
/
Example2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-19
|
2KB
|
75 lines
/* Example2 */
/* This example shows how to allocate and deallocate memory with help of */
/* the functions AllocRemember(), and FreeRemember(). */
#include <intuition/intuition.h>
#include <exec/memory.h>
struct IntuitionBase *IntuitionBase;
main()
{
/* Declare and initialize a pointer to the first Remember structure: */
struct Remember *remember = NULL;
/* Declare three memory pointers: */
CPTR memory1, memory2, memory3;
/* Open the Intuition Library: */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 0 );
if( IntuitionBase == NULL )
exit(); /* Could NOT open the Intuition Library! */
/* Allocate 350 bytes of Chip memory, which is cleared: */
memory1 = AllocRemember( &remember, 350, MEMF_CHIP|MEMF_CLEAR );
if( memory1 == NULL )
{
CloseLibrary( IntuitionBase );
exit();
}
/* Allocate 900 bytes of memory (any type, Fast if possible): */
memory2 = AllocRemember( &remember, 900, MEMF_PUBLIC );
if( memory2 == NULL )
{
FreeRemember( &remember, TRUE );
CloseLibrary( IntuitionBase );
exit();
}
/* Allocate 100 bytes of Chip memory: *
memory3 = AllocRemember( &remember, 100, MEMF_CHIP );
if( memory3 == NULL )
{
FreeRemember( &remember, TRUE );
CloseLibrary( IntuitionBase );
exit();
}
/* Do whatever you want to do with the memory. */
/* Deallocate all memory with one single call: */
FreeRemember( &remember, TRUE );
/* Close the Intuition Library: */
CloseLibrary( IntuitionBase );
}